﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using MySql.Data.MySqlClient;
using Microsoft.Reporting.WinForms;


namespace TMS
{
    public partial class PrintOfferControl : UserControl
    {
        DataGridViewRow row = new DataGridViewRow();
        public PrintOfferControl()
        {
            InitializeComponent();
        }

        public PrintOfferControl(DataGridViewRow row)
        {
            InitializeComponent();
            this.row = row;
        }

        private void repOffer_Load(object sender, EventArgs e)
        {
            ReportParameter name = new ReportParameter("OfferPartner",row.Cells[1].Value.ToString());
            ReportParameter offerNo = new ReportParameter("OfferNo", row.Cells[0].Value.ToString());
            ReportParameter date = new ReportParameter("Date", row.Cells[5].Value.ToString());
            ReportParameter price = new ReportParameter("Price", row.Cells[2].Value.ToString());
            ReportParameter VAT = new ReportParameter("VAT", row.Cells[3].Value.ToString());
            ReportParameter priceAndVAT = new ReportParameter("PriceAndVAT", row.Cells[4].Value.ToString());
            ReportParameter RokNaZavrsuvanje = new ReportParameter("RokNaZavrsuvanje", row.Cells[6].Value.ToString());
            ReportParameter VaznostNaPonudata = new ReportParameter("VaznostNaPonudata", row.Cells[7].Value.ToString());
            ReportParameter NacinNaPlakanje = new ReportParameter("NacinNaPlakanje", row.Cells[8].Value.ToString());
            ReportParameter Garancija = new ReportParameter("Garancija", row.Cells[9].Value.ToString());
            ReportParameter ActiveUser = new ReportParameter("ActiveUser", row.Cells[10].Value.ToString());
            ReportParameter Description = new ReportParameter("Description", row.Cells[11].Value.ToString());
            ReportParameter Request = new ReportParameter("Request", row.Cells[12].Value.ToString());
            ReportParameter Note = new ReportParameter("Note", row.Cells[13].Value.ToString());
            string connString = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;
            MySqlDataAdapter MyDA = new MySqlDataAdapter();

            MySqlConnection mysqlCon = new MySqlConnection(connString);
            mysqlCon.Open();


            string sqlSelectAll = "SELECT * from offered_products WHERE offerID='" + row.Cells[0].Value.ToString()+"'";
            MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mysqlCon);


            DataSet table = new DataSet();
            MyDA.Fill(table);


            mysqlCon.Close();
            this.repOffer.LocalReport.SetParameters(name);
            this.repOffer.LocalReport.SetParameters(offerNo);
            this.repOffer.LocalReport.SetParameters(date);
            this.repOffer.LocalReport.SetParameters(price);
            this.repOffer.LocalReport.SetParameters(VAT);
            this.repOffer.LocalReport.SetParameters(priceAndVAT);
            this.repOffer.LocalReport.SetParameters(RokNaZavrsuvanje);
            this.repOffer.LocalReport.SetParameters(VaznostNaPonudata);
            this.repOffer.LocalReport.SetParameters(NacinNaPlakanje);
            this.repOffer.LocalReport.SetParameters(Garancija);
            this.repOffer.LocalReport.SetParameters(ActiveUser);
            this.repOffer.LocalReport.SetParameters(Description);
            this.repOffer.LocalReport.SetParameters(Request);
            this.repOffer.LocalReport.SetParameters(Note);

            ReportDataSource rds = new ReportDataSource("DS1", table.Tables[0]);

            this.repOffer.LocalReport.DataSources.Add(rds);
            this.repOffer.RefreshReport();
            
        }

      

        private void ToStBack_Click(object sender, EventArgs e)
        {
            if (Program.GetMainForm.Back())
                this.Dispose();
        }



    }
}
